package com.yb0os1.controller.admin;

import com.yb0os1.constant.MessageConstant;
import com.yb0os1.result.Result;
import com.yb0os1.serve.DishServe;
import com.yb0os1.utils.AliOssUtil;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Objects;

@RestController
@RequestMapping("/admin/common")
public class CommonController {
    @Autowired
    private AliOssUtil aliOssUtil;

    @PostMapping("/upload")
    @Operation(summary = "文件上传")
    public Result<String> uploadFile(MultipartFile file){
        String image =aliOssUtil.upload(file);
        if (Objects.equals(image, MessageConstant.UPLOAD_FAILED))return Result.error(image);
        return Result.success(image);
    }
}
